package top.wanzc.java.basic.jdk9.to17.feature;

import java.util.function.Predicate;
import java.util.stream.Stream;

public class StreamEnhancement {
	
	public static void main(String[] args) {
		test();
	}
	
	public static void test() {
		System.out.println("------");
		Stream.of(1, 2, 3, 4, 5)
			.takeWhile(i -> i != 3)
			.forEach(i -> System.out.println(i));
			//.forEach(System.out::println);
		/* 输出结果：1 2*/
		
		System.out.println("------");
		Stream.of(1, 2, 3, 4, 5)
		.filter(Predicate.not( i -> i > 3))
		.forEach(i -> System.out.println(i));
		
		
		System.out.println("------");
		Stream.of(1, 2, 3, 4, 5)
		.dropWhile(i -> i != 3)
		.forEach(i -> System.out.println(i));
		System.out.println("------");
		Stream.iterate("1",  b -> b + "0").limit(3).forEach(System.out::println);
		Stream.iterate("1", a -> !"100".equals(a),  b -> b + "0").limit(3).forEach(System.out::println);
		
		System.out.println("------");
		Stream.ofNullable(null).forEach(System.out::println); // 没有任何输出
		Stream.ofNullable("xiaocao").forEach(System.out::println);
	}
}
